package org.jluzhCS.mylogin.action;

import org.jluzhCS.mylogin.domain.User;
import java.util.List;
import java.util.Map;

import org.jluzhCS.mylogin.service.UserService;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;

public class loginAction implements Action
{

    private User user;
    private List<User> allUser;

    public User getUser()
    {
	return user;
    }

    public void setUser(User user)
    {
	this.user = user;
    }

    @Override
    public String execute() throws Exception
    {
	UserService us = new UserService();
	Integer id = us.ValidLogin(user);
	if (id > 0)
	{
	    ActionContext ac = ActionContext.getContext();
	    ac.getSession().put("userType", getUser().getType());
	    return SUCCESS;
	}
	return ERROR;
    }

    public String showUsers() throws Exception
    {
	UserService us = new UserService();
	setAllUser(us.getAllUser());
	return SUCCESS;
    }

    public List<User> getAllUser()
    {
	return allUser;
    }

    public void setAllUser(List<User> allUser)
    {
	this.allUser = allUser;
    }

}
